package com.xu.system.model.convert;

import com.xu.mybatis.model.PageInfo;
import com.xu.system.model.entity.SysDict;
import com.xu.system.model.entity.SysDictItem;
import com.xu.system.model.pojo.dict.AddDictItemReq;
import com.xu.system.model.pojo.dict.AddDictReq;
import com.xu.system.model.pojo.dict.DictItemVo;
import com.xu.system.model.pojo.dict.DictVo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

/**
 * 字典pojo转化
 *
 * @Author: 许乾伟
 * @Date: 2024/4/5 13:15
 */
@Mapper(componentModel = "spring")
public interface DictConvert {
    @Mappings({
            @Mapping(target = "createBy", expression = "java(com.xu.security.utils.SecurityUtils.getUserId())"),
            @Mapping(target = "createTime", expression = "java(java.time.LocalDateTime.now())"),
            @Mapping(target = "updateBy", expression = "java(com.xu.security.utils.SecurityUtils.getUserId())"),
            @Mapping(target = "updateTime", expression = "java(java.time.LocalDateTime.now())"),
    })
    SysDict toSysDict(AddDictReq data);

    @Mappings({
            @Mapping(source = "id", target = "dictId"),
            @Mapping(source = "updateTime", target = "updateTime", dateFormat = "yyyy-MM-dd HH:mm:ss")
    })
    DictVo toDictVo(SysDict data);

    PageInfo<DictVo> toDictVoPage(PageInfo<SysDict> pageData);

    @Mappings({
            @Mapping(target = "createBy", expression = "java(com.xu.security.utils.SecurityUtils.getUserId())"),
            @Mapping(target = "createTime", expression = "java(java.time.LocalDateTime.now())"),
            @Mapping(target = "updateBy", expression = "java(com.xu.security.utils.SecurityUtils.getUserId())"),
            @Mapping(target = "updateTime", expression = "java(java.time.LocalDateTime.now())"),
    })
    SysDictItem toSysDictItem(AddDictItemReq data);

    @Mappings({
            @Mapping(source = "id", target = "dictItemId"),
            @Mapping(source = "updateTime", target = "updateTime", dateFormat = "yyyy-MM-dd HH:mm:ss")
    })
    DictItemVo toDictItemVo(SysDictItem data);

    PageInfo<DictItemVo> toDictItemVoPage(PageInfo<SysDictItem> pageData);
}
